<?
class JCAT_Archive
{
	function JCAT_Archive($sPath,$nType=self::SAVE)
	{
		$this->sPath = $sPath ;
		$this->nType = $nType ;
	}
	
	const SAVE = 1 ;
	const LOAD = 2 ;
	
	private $nType ;
	private $sPath ;
	
	private $arrData = array() ;
	
	function Value($sKey,&$sValue)
	{
		if($this->IsSave())
			$this->arrData[$sKey] = $sValue ;
		else
			$sValue = $this->arrData[$sKey] ;
	}	
	
	function Serialize()
	{
		file_put_contents( $this->sPath, base64_encode(serialize($this->arrData)) ) ;
		// print_r($this->arrData) ;
	}

	function Unserialize()
	{
		$this->arrData = unserialize( base64_decode(file_get_contents($this->sPath)) ) ;
		// print_r($this->arrData) ;
	}
	
	function IsSave()
	{ return ($this->nType==self::SAVE) ; }
	function IsLoad()
	{ return ($this->nType==self::LOAD) ; }
	
	function DoIt()
	{
		if($this->IsSave())
			$this->Serialize() ;
		else
			$this->Unserialize() ;
	}
}
?>